﻿package mortal.game.view.guide.guideUse
{
    import com.mui.controls.*;
    import extend.language.*;
    import flash.events.*;
    import flash.geom.*;
    import flash.text.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.component.gconst.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.utils.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.button.*;
    import mortal.game.view.guide.*;
    import mortal.mvc.core.*;
    import mortal.mvc.interfaces.*;

    public class GuideItemUseWin extends GuideUseWinBase
    {
        private var _txtTips:GTextFiled;
        private var _txtName:GTextFiled;
        private var _txtItemDesc:GTextFiled;
        private var _btnEquip:GLabelButton;
        private var _numericStepper:GNumericStepper;
        private var _useBlukTxt:GTextFiled;

        public function GuideItemUseWin(param1:ILayer = null)
        {
            super(param1);
            return;
        }// end function

        override protected function updateData() : void
        {
            this._txtName.htmlText = _itemData.itemInfo.htmlName;
            this._txtName.y = 67;
            var _loc_1:* = _itemData.itemInfo.alyDesc();
            if (_loc_1)
            {
                this._txtItemDesc.htmlText = Language.getStringByParam(21004, _loc_1);
            }
            else
            {
                this._txtItemDesc.htmlText = "";
            }
            var _loc_2:int = 20;
            if (this._txtItemDesc.numLines == 3)
            {
                this._txtItemDesc.y = 90;
                this._txtName.y = 63;
                _loc_2 = 17;
            }
            else if (this._txtItemDesc.numLines >= 4)
            {
                this._txtItemDesc.y = 82;
                this._txtName.y = 59;
                _loc_2 = 12;
            }
            else
            {
                this._txtItemDesc.y = 100;
            }
            if (_guideUseItemData.showTxt)
            {
                this._txtTips.htmlText = _guideUseItemData.showTxt;
            }
            else
            {
                this._txtTips.text = Language.getString(21006);
            }
            if (ItemsUtil.isCanBulkUse(_itemData))
            {
                var _loc_3:Boolean = true;
                this._numericStepper.visible = true;
                this._useBlukTxt.visible = _loc_3;
                this.updateNumericStepper();
                var _loc_3:* = this._txtItemDesc.y + this._txtItemDesc.textHeight + _loc_2;
                this._numericStepper.y = this._txtItemDesc.y + this._txtItemDesc.textHeight + _loc_2;
                this._useBlukTxt.y = _loc_3;
                this.setSize(291, this._useBlukTxt.height + this._useBlukTxt.y + 108);
                NetDispatcher.addCmdListener(ServerCommand.BackPackItemsReduction, this.onDelItemHandler);
            }
            else
            {
                var _loc_3:Boolean = false;
                this._numericStepper.visible = false;
                this._useBlukTxt.visible = _loc_3;
                _item.amount = 1;
                this.setSize(291, this._txtItemDesc.textHeight + this._txtItemDesc.y + 118);
            }
            return;
        }// end function

        override protected function updatePos() : void
        {
            super.updatePos();
            if (this._btnEquip)
            {
                this._btnEquip.y = this.height - this._btnEquip.height - 12 + _windowBg.y;
            }
            return;
        }// end function

        private function updateNumericStepper() : void
        {
            var _loc_1:* = Cache.instance.pack.backPackCache.getItemDataByUid(_itemData.serverData.uid);
            if (_loc_1)
            {
                this._numericStepper.maximum = _loc_1.serverData.itemAmount;
                this._numericStepper.minimum = 1;
                this._numericStepper.value = _guideUseItemData.isUseMaxNum ? (_loc_1.serverData.itemAmount) : (1);
                _item.amount = _loc_1.serverData.itemAmount;
            }
            return;
        }// end function

        private function onDelItemHandler(param1:Array) : void
        {
            var _loc_2:* = param1[0];
            if (_loc_2.serverData.uid == _itemData.serverData.uid)
            {
                this.updateNumericStepper();
            }
            return;
        }// end function

        override protected function timerOut() : void
        {
            if (isDisposed)
            {
                return;
            }
            if (_itemData == null)
            {
                hide();
                return;
            }
            if (ItemsUtil.isMountAdvanced(_itemData))
            {
            }
            else
            {
                this.useItemHandler(null);
            }
            hide();
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            var _loc_1:* = GlobalStyle.textFormatBai.center();
            this._txtTips = UIFactory.gTextField(Language.getString(21007), 30, 36, 250, 40, this, _loc_1.left());
            this._txtName = UIFactory.gTextField("", 37, 67, 220, 20, this, _loc_1.center());
            this._txtItemDesc = UIFactory.gTextField("", 30, 100, 225, 150, this, _loc_1.left());
            this._txtItemDesc.autoSize = TextFieldAutoSize.LEFT;
            this._txtItemDesc.wordWrap = true;
            this._txtItemDesc.multiline = true;
            this._useBlukTxt = UIFactory.gTextField(Language.getString(21008), 80, 67, 220, 20, this, _loc_1.left());
            this._numericStepper = UIFactory.gNumericStepper(150, 79, 50, 20, this, int.MAX_VALUE, 1, "NumericStepper", _loc_1);
            this._btnEquip = UIFactory.gLabelButton(ImagesConst.GuideItemLabel_Use, GLabelButton.gLoadingButton, ResFileConst.TaskContinue, 95, 185, 103, 40, this, "GImageBitmap");
            this._btnEquip.configEventListener(MouseEvent.CLICK, this.useItemHandler);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._txtTips.dispose(param1);
            this._txtTips = null;
            if (this._btnEquip)
            {
                this._btnEquip.dispose(param1);
                this._btnEquip = null;
            }
            this._txtName.dispose(param1);
            this._txtName = null;
            this._txtItemDesc.dispose(param1);
            this._txtItemDesc = null;
            this._numericStepper.dispose(param1);
            this._numericStepper = null;
            this._useBlukTxt.dispose(param1);
            this._useBlukTxt = null;
            NetDispatcher.removeCmdListener(ServerCommand.BackPackItemsReduction, this.onDelItemHandler);
            super.disposeImpl(param1);
            return;
        }// end function

        private function useItemHandler(event:MouseEvent) : void
        {
            var _loc_2:Point = null;
            disposeTimer();
            if (ItemsUtil.isCanBulkUse(_item.itemData))
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.BackPack_BulkUse, {itemData:_item.itemData, amount:this._numericStepper.value}));
            }
            else
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.Guide_ItemUseClick, _item.itemData));
            }
            if (ItemsUtil.isDrugMana(_item.itemData) || ItemsUtil.isDrugManaBag(_item.itemData))
            {
                _loc_2 = _item.localToGlobal(GameConst.yellowPoint);
                _loc_2.x = _loc_2.x + 20;
                _loc_2.y = _loc_2.y + 20;
                GuideFlyEffect.instance.work(_loc_2, new Point(270, 56), 18, 80, null, GuideFlyEffect.color_Blue);
            }
            else if (ItemsUtil.isDrugLife(_item.itemData) || ItemsUtil.isDrugLifeBag(_item.itemData))
            {
                _loc_2 = _item.localToGlobal(GameConst.yellowPoint);
                _loc_2.x = _loc_2.x + 20;
                _loc_2.y = _loc_2.y + 20;
                GuideFlyEffect.instance.work(_loc_2, new Point(255, 56), 18, 80, null, GuideFlyEffect.color_Red);
            }
            this.hide();
            return;
        }// end function

    }
}
